//
//  EditorGroupInfoViewController.m
//  AAIM
//
//  Created by awh on 2019/12/3.
//  Copyright © 2019年 AAIM. All rights reserved.
//

#import "EditorGroupInfoViewController.h"

@interface EditorGroupInfoViewController ()<UITextFieldDelegate>
@property(nonatomic,strong)UITextField*changeTF;
@end

@implementation EditorGroupInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString * placeholderStr;
    if ([_type isEqualToString:@"groupName"]) {
        self.gk_navTitle=@"修改群名称";
        placeholderStr=@"请输入群名称";
    }else
    {
        self.gk_navTitle=@"修改群公告";
        placeholderStr=@"请输入群公告";

    }
    
    _changeTF=[[UITextField alloc]initWithFrame:CGRectMake(15, NavigationBarHeight+30, SCREEN_WIDTH-30, 40)];
    _changeTF.placeholder = placeholderStr;
    _changeTF.font = kMainFont(15);
    _changeTF.textColor = KHEXCOLOR(@"#262B2F");
    _changeTF.delegate = self;
    _changeTF.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:self.changeTF];
    
     UIView*lineV=[[UIView alloc]initWithFrame:CGRectMake(_changeTF.x, _changeTF.bottom, _changeTF.width, 0.5)];
    lineV.backgroundColor=KHEXCOLOR(IM_Color_SeparateLine);
    [self.view addSubview:lineV];
    
    // 导航右按钮
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"保存" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(saveClick:) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn sizeToFit];
    [rightBtn setBackgroundColor:KHEXCOLOR(kMainColor)];
    rightBtn.frame = CGRectMake(0, 0, 40, 25);
    rightBtn.layer.cornerRadius = 2;
    rightBtn.layer.masksToBounds = YES;
    rightBtn.titleLabel.font = kMainFont(12);
    rightBtn.jk_touchAreaInsets = UIEdgeInsetsMake(20, 20, 20, 20);
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.gk_navigationItem.rightBarButtonItem = rightItem;
    // Do any additional setup after loading the view.
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

{
    
    if (range.length + range.location > textField.text.length) {
        
        return NO;
        
    }
    
    NSUInteger length = textField.text.length + string.length - range.length;
    if ([_type isEqualToString:@"groupName"]) {
        return length <= 30;
    }else{
        return YES;
    }
    
    
}

-(void)saveClick:(UIButton*)sender
{
    NSString * alertStr;
    if ([_type isEqualToString:@"groupName"]) {
        alertStr=@"群名称不能为空";
    }else
    {
        alertStr=@"群公告不能为空";
    }
    if ([NSObject ldy_isEmpty:_changeTF.text]) {
        [self showTipHudWithText:alertStr];
        return;
    }
    if (self.editorBlock) {
        self.editorBlock(_changeTF.text);
    }
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
    
//    self.navigationController.navigationBar.translucent=NO;
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
